<?php

$group		= gpc_getIntGet("group",-10);
$status		= gpc_getIntGet("status",-10);

List_Accounts();

function List_Accounts()
{
	global $accounts,$posts_per_page_post,$page;
	global $dbsql,$group,$status;

    $group  = intval($group);
    $status = intval($status);

	$accounts=array();
	$sql_where = "from tblaccount where iAccountId>1 ";

	if($group!=-10)
	{
		$sql_where.=" and iGroupId= $group ";
	}
	if($status>-10)
	{
		$sql_where.=" and iStatus='$status' ";
	}

	$sql_select = "select count(iAccountId) as count  ".$sql_where;
	$rs=$dbsql->query($sql_select);
	$result = $dbsql->fetch_array($rs);
	$count_all=$result['count'];

	list($limit_st,$limit_le)	=Slit_Page($count_all);

	//-----------------------------------------------------
	$sql_select = "select * ".$sql_where;

	$sql_select.=" order by iAccountId ASC limit $limit_st,$limit_le";

	$rs=$dbsql->query($sql_select);

	while ( $result = $dbsql->fetch_array($rs) )
	{
		$result['cGroupName']=getGroupName($result['iGroupId']);
		$accounts[] = $result;
	}
	return  $accounts;
}

function getGroupName($id)
{
global $dbsql;
    $id     = intval($id);
	$sql_select="select cGroupName from tblpermission where iId='$id'";
	$rs=$dbsql->query($sql_select);
	if($result=$dbsql->fetch_array($rs))
	{
		return $result['cGroupName'];
	}
	return "Customer";
}

?>